package com.finalist.captcha.service;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.google.code.ssm.api.CacheName;
import com.google.code.ssm.api.InvalidateSingleCache;
import com.google.code.ssm.api.ParameterValueKeyProvider;
import com.google.code.ssm.api.ReadThroughSingleCache;
import com.google.code.ssm.api.ReturnDataUpdateContent;
import com.google.code.ssm.api.UpdateSingleCache;
import com.octo.captcha.service.captchastore.CaptchaAndLocale;

@Service("captchaCacheService")
public class CaptchaCacheServiceImpl implements CaptchaCacheService {

	private static Log log = LogFactory.getLog(CaptchaCacheServiceImpl.class);
	public static final int HALF_HOUR = 10 * 60 * 1000; // 换算成毫秒
	public static final String CACHE_NAME = "isecurity";
	public static final String NS_CAPTCHA = "captcha";
	
	@CacheName(value = CACHE_NAME)
	@ReturnDataUpdateContent
	@UpdateSingleCache(namespace = NS_CAPTCHA, expiration = HALF_HOUR)
	public CaptchaAndLocale storeCaptcha(@ParameterValueKeyProvider String id, CaptchaAndLocale captcha) {
		log.info("[captchaCacheService] store captcha:" + id);
		return captcha;
	}

	@Override
	@CacheName(value = CACHE_NAME)
	@ReadThroughSingleCache(namespace = NS_CAPTCHA, expiration = HALF_HOUR)
	public CaptchaAndLocale getCaptcha(@ParameterValueKeyProvider String id) {
		log.info("[captchaCacheService] get captcha:" + id);
		return null;
	}
	
	@CacheName(value = CACHE_NAME)
	@InvalidateSingleCache(namespace = NS_CAPTCHA)
	public CaptchaAndLocale removeCaptcha(@ParameterValueKeyProvider String id) {
		log.info("[captchaCacheService] remove captcha ");
		return null;
	}

}
